package com.lagou.controller;

import com.lagou.filter.TransportIPFilter;
import com.lagou.service.TestService;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.rpc.Filter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class TestController {
    @Autowired
    TestService testService;

    @RequestMapping("/dubbo")
    public String testIP(HttpServletRequest request) {
        TransportIPFilter ipFilter = (TransportIPFilter) ExtensionLoader.getExtensionLoader(Filter.class).getExtension("IPFilter");
        ipFilter.setIPHolder(request.getRemoteAddr());
        return testService.test();
    }

    @RequestMapping("/start")
    public String tpStart() {
        testService.executeMultiThread();
        return "start success";
    }

    @RequestMapping("/stop")
    public String tpStop() {
        testService.stopMultiThread();
        return "stop success";
    }
}
